<?php
class Bootstrap extends 
	Zend_Application_Bootstrap_Bootstrap 
{
	
	protected function _initDb ()
    {
        $db = $this->getPluginResource('db')->getDbAdapter();
        $db->query("SET NAMES 'utf8'");
        Zend_Db_Table::setDefaultAdapter($db);
        Zend_Registry::set('db', $db);
    }
        
	protected function _initSession ()
    {
        $session = new Zend_Session_Namespace( 'Adm');
        Zend_Registry::set('session', $session);
    }
        
	protected function _initConfig() 
	{
	    $config = new Zend_Config($this->getOptions());
	    Zend_Registry::set('configuration', $config);
	}
    	
	protected function _initView ()
	{
    	
        // Initialize view
        $view = new Zend_View();
        $view->doctype('XHTML1_STRICT');
        $view->headTitle('VotoSecreto');
        // Add it to the ViewRenderer
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
        $viewRenderer->setView($view)    ;

        $view->addHelperPath('My/View/Helper', 'My_View_Helper_');
        $view->addHelperPath( dirname(__FILE__) . '/views/helpers', 'Adm_View_Helper_');
        $view->addHelperPath( dirname(dirname(__FILE__)) . '/del/views/helpers', 'Del_View_Helper_');
        //ZendX_JQuery::enableView($view);
        // Return it, so that it can be stored by the bootstrap
        return $view;
    } 
    
//	protected fProductosController.phpunction _initAutoloaders()
//	{ 
//		$this->getApplication()->setAutoloaderNamespaces(array('My_'));
//		return $this;
//	}
    	
	protected function _initActionHelpers() 
	{
		Zend_Controller_Action_HelperBroker::addPrefix ( 'My_Controller_Action_Helper' );
		
		$path = dirname(__FILE__) 	. DIRECTORY_SEPARATOR .
				'controllers'		. DIRECTORY_SEPARATOR .
				'helpers';
				
		Zend_Controller_Action_HelperBroker::addPath($path, 'Adm_Action_Helper');
		
		Zend_Controller_Action_HelperBroker::getStaticHelper('acl');
		Zend_Controller_Action_HelperBroker::getStaticHelper('BaseInit');
	}	
    
	protected function _initModuleAutoloader() 
    {
		
    	$del = new Zend_Application_Module_Autoloader(array(
			'namespace' => 'Vs' , 
			'basePath' => dirname(dirname(__FILE__)) . '/vs'
		));
    	
//		$del->addResourceType('collection', 'models/collections', 'Model_Collection');
		
    	$web = new Zend_Application_Module_Autoloader(array(
			'namespace' => 'Web' , 
			'basePath' => dirname(dirname(__FILE__)) . '/web'
		));
    	
    	$adm = new Zend_Application_Module_Autoloader(array(
			'namespace' => 'Adm' , 
			'basePath' => dirname(dirname(__FILE__)) . '/adm'
		));
    	
    	$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
		    'basePath'  => dirname(dirname(dirname(__FILE__))) . '/library/',
		    'namespace' => 'My',
		));
    	
	}	
	
	protected function _initNavigation() 
	{
		$this->bootstrap ( 'layout' );
		$layout = $this->getResource ( 'layout' );
		$view = $layout->getView ();
		$config = new Zend_Config_Xml ( APPLICATION_PATH . '/configs/navigation.xml', 'nav' );
		
		$container = new Zend_Navigation ( $config );
		
		$view->navigation ( $container );
		Zend_Registry::set ( 'Zend_Navigation', $container );
	
	}
	
//	protected function _initTranslate()
//	{	
//		$lang = $this->getOption('language');
//		
//		$file1 = implode( DIRECTORY_SEPARATOR, array( dirname(APPLICATION_PATH) , 'del', 'languages', "validate.{$lang}.php"));
//		$file2 = implode( DIRECTORY_SEPARATOR, array( dirname(APPLICATION_PATH) , 'del', 'languages', "common.{$lang}.php"));
//		$file3 = implode( DIRECTORY_SEPARATOR, array( dirname(__FILE__) , 'languages', "{$lang}.php"));
//		
//		$translate = new Zend_Translate('array', $file1 , $lang);
//		$translate->addTranslation(
//			array(
//		        'content' => $file2,
//		        'locale'  => $lang
//		    )
//		);	
//		
//		$translate->addTranslation(
//			array(
//		        'content' => $file3,
//		        'locale'  => $lang
//		    )
//		);	
//		
//		Zend_Registry::set('Zend_Translate', $translate);
//		Zend_Form::setDefaultTranslator($translate);
//	
//	}
	
	protected function _initLogger ()
    {
        $log = $this->getPluginResource('log')->getLog();
        
        Zend_Registry::set('Zend_Log', $log);
    }
    
	protected function _initJquery() {
		
		$this->bootstrap('view');
		
		$view = $this->getResource('view');
		
		ZendX_JQuery::enableView ( $view );
		
		return $view;
	}
	
}

